package cn.com.dhc.danlu.model;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.List;

/**
 * 品类实体
 * Created by wisek on 2016/11/25.
 */
public class CategoryModel implements Parcelable, IChildable {
    //名称
    public String name;
    //代码
    public String code;
    //图片host地址
    public String baseImgStr;
    //图片地址
    public String iconURL;
    //子品类
    public List<CategoryModel> categoryModels;

    @Override
    public String getName() {
        return name;
    }

    @Override
    public List<CategoryModel> getChildrens() {
        return categoryModels;
    }

    @Override
    public String getText() {
        return name;
    }

    @Override
    public String getSbuText() {
        return null;
    }

    @Override
    public String getIconURL(){
        return iconURL;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        CategoryModel that = (CategoryModel) o;

        return code != null ? code.equals(that.code) : that.code == null;
    }

    @Override
    public int hashCode() {
        return code != null ? code.hashCode() : 0;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.name);
        dest.writeString(this.code);
        dest.writeString(this.baseImgStr);
        dest.writeString(this.iconURL);
        dest.writeTypedList(this.categoryModels);
    }

    public CategoryModel() {
    }

    protected CategoryModel(Parcel in) {
        this.name = in.readString();
        this.code = in.readString();
        this.baseImgStr = in.readString();
        this.iconURL = in.readString();
        this.categoryModels = in.createTypedArrayList(CategoryModel.CREATOR);
    }

    public static final Creator<CategoryModel> CREATOR = new Creator<CategoryModel>() {
        @Override
        public CategoryModel createFromParcel(Parcel source) {
            return new CategoryModel(source);
        }

        @Override
        public CategoryModel[] newArray(int size) {
            return new CategoryModel[size];
        }
    };
}
